﻿using System.Drawing;

namespace InfoPathHelpers.RepeatingTable.Paginator
{
    public class GraphicsTextMeasurer : ITextMeasurer
    {
        Graphics _Graphics;

        public GraphicsTextMeasurer()
        {
            _Graphics = Graphics.FromImage(new Bitmap(1, 1));
        }

        public GraphicsTextMeasurer(Font font)
        {
            Font = font;
            _Graphics = Graphics.FromImage(new Bitmap(1, 1));
        }

        public Font Font { get; set; }

        public int Measure(string text)
        {
            return _Graphics.MeasureString(text, Font).ToSize().Width;
        }

        public int Measure(string text, Font font)
        {
            return _Graphics.MeasureString(text, font).ToSize().Width;
        }
    }
}
